var _ = require('lodash');
var path = require('path');
var webpack = require('webpack');
var makeConfig = require("./base.config.js").makeConfig;
var ExtractTextPlugin = require("extract-text-webpack-plugin");
var HtmlWebpackPlugin = require('html-webpack-plugin');
var HtmlWebpackHarddiskPlugin = require('html-webpack-harddisk-plugin');
var baseConfig = require("./base.config.js").config

var entries = _.mapValues(baseConfig.entry, function (v, k) {
  return ['webpack-hot-middleware/client', 'webpack/hot/dev-server', v];
});

var keys = _.keys(baseConfig.entry);
keys.push('vendors');

var devConfig = makeConfig({
  devtool: "eval-source-map",
  entry: entries,
  output: {
    publicPath: '/'
  },
  plugins: [
    new webpack.DefinePlugin({
      "process.env": {
        NODE_ENV: JSON.stringify('development')
      }
    }),
    new ExtractTextPlugin("vendors.css"),
    new webpack.HotModuleReplacementPlugin(),
    new webpack.optimize.CommonsChunkPlugin({
      name: 'vendors',
      filename: 'vendors.js',
      // (Modules must be shared between 3 entries)
      minChunks: 2
      // (Only use between these entries)
      // chunks: ["index", "kitchensink"]
    }),
    new HtmlWebpackPlugin({
      alwaysWriteToDisk: true,
      chunks:keys,
      hash:true,
      filename: './.temp/index.html',//分模块文件夹
      template: './template.html'
    }),
    new HtmlWebpackHarddiskPlugin()
  ]
});

module.exports = devConfig
